package com.mvc.service.impl;

import com.mvc.mapper.ImgMapper;
import com.mvc.mapper.SkuMapper;
import com.mvc.mapper.SpuMapper;
import com.mvc.model.ImgModel;
import com.mvc.model.ItemModel;
import com.mvc.model.SkuModel;
import com.mvc.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @ProjectName: dior
 * @Package: com.mvc.service.impl
 * @ClassName: ItemServiceImpl
 * @Description: 商品详情接口
 * @Author: lenovo
 * @Date: 2021/12/16 21:54
 * @Version: 1.0
 **/
@Service
public class ItemServiceImpl implements ItemService {
    @Autowired
    SpuMapper spuMapper;
    @Autowired
    SkuMapper skuMapper;
    @Autowired
    ImgMapper imgMapper;
    /**
     * 添加商品信息
     *
     * @param itemModel 商品信息参数对象
     * @return 影响行数
     */
    @Override
    public Integer itemAdd(ItemModel itemModel) {
        Integer row=null;
        itemModel.setCreate_time(new Date());
        itemModel.setUpdate_time(new Date());
        spuMapper.insertSpu(itemModel);
        Integer spuId=itemModel.getId();
        List<SkuModel> skuList=itemModel.getSkuList();
        for (SkuModel sku:skuList){
            sku.setSpu_id(spuId);
            skuMapper.insertSku(sku);
            Integer skuId=sku.getId();
            List<ImgModel> imgList=sku.getImgList();
            for (ImgModel img:imgList){
                img.setShopId(skuId);
             row= imgMapper.insertImg(img);
            }
        }
        return row;
    }
}
